package com.zwj.spring_study.a01;

import com.zwj.spring_study.a01.entity.User;
import com.zwj.spring_study.a01.event.UserRegisteredEvent;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 用户注册功能
 * @author 张文接
 * @version 1.0
 * @createTime 2024/5/8 23:15
 */
@Slf4j
@Data
@Component
public class Component2 {
    /**
     * 应用事件发布
     */
    @Resource
    private ApplicationEventPublisher applicationEventPublisher;
    /**
     * 用户属性
     */
    private User user;

    public Component2() {
        this.user = new User();
    }

    public void userRegister() {
        this.user.setName("admin");
        this.user.setAge(18);
        //发布用户注册事件
        log.info("用户开始注册");
        applicationEventPublisher.publishEvent(new UserRegisteredEvent(this));
    }
}
